package com.yksj.healthtalk.ui.server;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.math.NumberUtils;
import org.handmark.pulltorefresh.library.PullToRefreshBase;
import org.handmark.pulltorefresh.library.PullToRefreshListView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.universalimageloader.core.DefaultConfigurationFactory;
import org.universalimageloader.core.DisplayImageOptions;
import org.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.open.share.OpenManager;
import com.yksj.healthtalk.comm.BaseFragmentActivity;
import com.yksj.healthtalk.comm.ImageGalleryActivity;
import com.yksj.healthtalk.comm.ShareDialogFragment;
import com.yksj.healthtalk.net.http.AsyncHttpResponseHandler;
import com.yksj.healthtalk.net.http.HttpRestClient;
import com.yksj.healthtalk.net.http.JsonHttpResponseHandler;
import com.yksj.healthtalk.net.http.ObjectHttpResponseHandler;
import com.yksj.healthtalk.net.socket.SmartFoxClient;
import com.yksj.healthtalk.ui.R;
import com.yksj.healthtalk.ui.app.AppData;
import com.yksj.healthtalk.ui.news.NewsCommenActivity;
import com.yksj.healthtalk.utils.FileUtils;
import com.yksj.healthtalk.utils.ToastUtil;
import com.yksj.healthtalk.utils.WheelUtils;

/**
 * 新闻,活动内容显示页面
 * 
 * @author Tang
 */
public class ServerCenterContentActivity extends BaseFragmentActivity implements
		OnClickListener {
	boolean isCollection = false;//是否收藏了
	String newsId;
	String userId;
	int oride;
	TextView titleTextView;
	TextView contentTextView;
	TextView timeTextView;
	CheckBox collectionCheckBox;//收藏
	TextView shareTextView;//分享
//	TextView repeatTextView;//转发
	Button commenTextView;//评论
	NewsCommensAdapter adapter;
	ListView mListView;
	PullToRefreshListView refreshListView;
	LinearLayout mLinearLayout;//动态添加imageview
	PopupWindow mPopupWindow;
	View mShareView;
	JSONArray mImagePathArray;
	JSONObject mJsonObject;//新闻内容
	ImageLoader mImageLoader;
	DisplayImageOptions mDisplayImageOptions;
	List<String> urlList = new ArrayList<String>();
	private boolean isTrue;
	
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.news_content_layout);
		newsId = getIntent().getStringExtra("newsId");
		userId = SmartFoxClient.getLoginUserId();
		isTrue = getIntent().hasExtra("isTrue");//是否是从我的收藏中进入的
		try {
			mJsonObject=new JSONObject(getIntent().getStringExtra("content"));
		} catch (JSONException e) {
		}
		mImageLoader = ImageLoader.getInstance();
		mDisplayImageOptions = DefaultConfigurationFactory.createGalleryDisplayImageOptions(this);
		
		initView();
		onBundData();
		initData(String.valueOf(Integer.MAX_VALUE));
	}
	
	private void onUpdateCollectionNumber(){
		collectionCheckBox.setEnabled(false);
		if(collectionCheckBox.isChecked()) {
			actionForImage(newsId,userId,"saveCenterMerchantNewsCustomer");
		} else {
			actionForImage(newsId,userId,"deleteCenterMerchantNewsCustomer");
		}
		FileUtils.updateInterestCollection(newsId,collectionCheckBox.isChecked());
	}
	
	/**
	 * 收藏,取消收藏 分享转发
	 * @param picId
	 * @param userid
	 * @param type
	 * deleteCenterMerchantNewsCustomer
 		saveCenterMerchantNewsCustomer
 		updateCenterMerchantNewscount
	 */
	private void actionForImage(final String picId, String userid, final String type) {
		HttpRestClient.doHttpServerActionForNews(picId, userid,type,new AsyncHttpResponseHandler() {
			@Override
			public void onSuccess(int statusCode, String cotent) {
				if("1".equals(cotent)){
					onActionSucceed(cotent,type);
				}else{
					collectionCheckBox.setEnabled(true);
					collectionCheckBox.setChecked(!collectionCheckBox.isChecked());
					ToastUtil.showBasicShortToast(getApplicationContext(), "操作失败...");
				}
			}
		});
	}
	
	/**
	 * 收藏分享转发成功后返回内容
	 * @param object
	 * @param type
	 */
	private void onActionSucceed(String object, String type) {
		if(type.equalsIgnoreCase("updateCenterMerchantNewscount")){//分享
			/*String number = shareTextView.getText().toString();
			if(NumberUtils.isNumber(number)){
				int collectNumber = NumberUtils.toInt(number);
				++collectNumber;
				if(collectNumber < 0)collectNumber = 0;
				shareTextView.setText(String.valueOf(collectNumber));
			}*/
		}else{//取消收藏       收藏
			String number = collectionCheckBox.getText().toString();
			if(NumberUtils.isNumber(number)){
				int collectNumber = NumberUtils.toInt(number);
				if(collectionCheckBox.isChecked()){
					++collectNumber;
					if(collectNumber < 0)collectNumber = 0;
					collectionCheckBox.setText(String.valueOf(collectNumber));
					ToastUtil.showToastPanl("收藏成功");
				}else{
					--collectNumber;
					if(collectNumber < 0)collectNumber = 0;
					collectionCheckBox.setText(String.valueOf(collectNumber));
					ToastUtil.showToastPanl("取消收藏");
				}
			}
			collectionCheckBox.setEnabled(true);
		}
	}
	
	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.title_back:
			onBackPressed();
			break;
		case R.id.news_comment://新闻评论
			onComment(SmartFoxClient.getLoginUserId(),newsId,"0");
			break;
		case R.id.news_collection://收藏
			//收藏按钮 点击第一次为收藏,第二次为取消收藏，所以需要增加一个标志位isCollectButtonClicked     
			//true为已经点击了收藏
			onUpdateCollectionNumber();
			break;
		case R.id.news_share://分享
			onShareClick();
			break;
		case R.id.news_repeat://转发
			break;
		case R.id.news_share_sina:
			if(mPopupWindow!=null&&mPopupWindow.isShowing()){
				mPopupWindow.dismiss();
			}
			shareTxt(OpenManager.SINA_WEIBO);
			break;
		case R.id.news_share_qq:
			if(mPopupWindow.isShowing())mPopupWindow.dismiss();
			shareTxt(OpenManager.TENCENT_WEIBO);
			break;
		case R.id.news_share_renren:
			if(mPopupWindow.isShowing())mPopupWindow.dismiss();
			shareTxt(OpenManager.RENREN);
			break;
		case R.id.news_share_mesg:
			shareNewsByMessage();
			break;
		case R.id.invite_cancel:
			if(mPopupWindow.isShowing()){
				mPopupWindow.dismiss();
			}
			break;
		default:
			if(v instanceof ImageView){
				Intent intent = new Intent(this,ImageGalleryActivity.class);
				intent.putExtra(ImageGalleryActivity.URLS_KEY,urlList.toArray(new String[urlList.size()]));
				intent.putExtra(ImageGalleryActivity.TYPE_KEY,1);//0,1单个,多个
				 intent.putExtra("type", 1);
				startActivityForResult(intent,100);
			}
			break;
		}
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		switch(requestCode){
		case 1000:
			if(resultCode == RESULT_OK){
				adapter.clearData();
				initData(String.valueOf(Integer.MAX_VALUE));
			}
			break;
		}
		
	}
	
	private void initView(){
		initTitle();
		titleLeftBtn.setOnClickListener(this);
		titleTextV.setText("新闻发布");
	}
	
	private void onBundData(){
		refreshListView = (PullToRefreshListView)findViewById(R.id.listview);
		mListView = refreshListView.getRefreshableView();
		mListView.addHeaderView(onCreateContentView(),null,false);
		mListView.setAdapter(adapter = new NewsCommensAdapter(this));
		
		refreshListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2() {
			@Override
			public void onPullDownToRefresh(PullToRefreshBase refreshView) {
			}
			@Override
			public void onPullUpToRefresh(PullToRefreshBase refreshView) {
				int size = adapter.getCount();
				if(size > 1){
					String id;
					try {
						id = adapter.getReplyId(adapter.getItem(size-1));
						onDoQueryComment("1",id,"5");
					} catch (JSONException e) {
						refreshListView.onRefreshComplete();
					}
				}else{
					onDoQueryComment("0",String.valueOf(Long.MAX_VALUE),"10");
				}
			}
		});
	}
	
	/**
	 * 
	 * 发表评论
	 * @param userid
	 * @param newsid
	 * @param replyId
	 */
	private void onComment(String userid,String newsid,String replyId){
		Intent intent = new Intent(this,NewsCommenActivity.class);
		intent.putExtra("userId",userId);
		intent.putExtra("newsId",newsId);
		intent.putExtra("title", titleTextView.getText().toString());
		intent.putExtra("replyId",replyId);
		intent.putExtra("server","server");
		intent.putExtra("content", getIntent().getStringExtra("content"));
		startActivityForResult(intent,1000);
	}
	
	private boolean paseToNewId(String content){
		List<String> objet=new ArrayList<String>();
		try {
			JSONArray array=new JSONArray(content);
			for (int i = 0; i < array.length(); i++) {
				JSONObject object= (JSONObject) array.get(i);
				String string = object.getString("NEWS_ID");
				objet.add(string);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return objet.contains(newsId);
	}
	
	
	
	private void queryCollettion(){
		HttpRestClient.doHttpQueryCollection(userId,
				new ObjectHttpResponseHandler(this) {
			@Override
			public Object onParseResponse(String content) {
				return paseToNewId(content);
			}
			@Override
			public void onSuccess(int statusCode, Object response) {
				super.onSuccess(statusCode, response);
				collectionCheckBox.setChecked((Boolean) response);
			}
		});
	}
	
		private void initData(final String oridenum){
		
		HttpRestClient.doHttpQueryServerNewsContentDetail(userId,newsId,oridenum,"queryCenterMerchantNewsReply",
				new ObjectHttpResponseHandler(this) {
			@Override
			public Object onParseResponse(String cotent) {
					onParseData(mJsonObject,cotent);
				return cotent;
			}
			public void onSuccess(int statusCode, Object response) {
				try {
					JSONObject object=new JSONObject((String)response);
					commenTextView.setText(object.getString("COMMENT_COUNT"));
					JSONArray array=(JSONArray)object.getJSONArray("CENTER_MERCHANT_NEWS_REPLY");
					adapter.onDataChange(array,0);
					if(array.length()>0)
					oride=Integer.parseInt(array.getJSONObject(array.length()-1).getString("REPLY_ID"));
					queryCollettion();
				} catch (JSONException e) {
					e.printStackTrace();
				}
			};
		}
		);
	}
	
	/**
	 * 分享
	 */
	private void onShareClick(){
		if(mPopupWindow == null){
			mShareView = LayoutInflater.from(ServerCenterContentActivity.this).inflate(R.layout.news_share_window_layout,null);
			mPopupWindow = new PopupWindow(mShareView, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
			mShareView.findViewById(R.id.news_share_sina).setOnClickListener(this);
			mShareView.findViewById(R.id.news_share_qq).setOnClickListener(this);
			mShareView.findViewById(R.id.news_share_renren).setOnClickListener(this);
			mShareView.findViewById(R.id.news_share_mesg).setOnClickListener(this);
			mPopupWindow.setOutsideTouchable(true);
			mShareView.findViewById(R.id.invite_cancel).setOnClickListener(this);
			WheelUtils.setPopeWindow(this,mShareView,mPopupWindow);
		}else{
			WheelUtils.setPopeWindow(this,mShareView,mPopupWindow);
		}
	}
	String picPath="";
	private ImageView imageViewContent;
	private void onParseData(JSONObject data,String mun){
		try {
			final String cllections;
			final String comments;
			final String shares;
			final String time;
			final String title;
			final String content ;
			JSONObject objt=new JSONObject(mun);
			if(isTrue){
				cllections = data.optString("COLLECTION_COUNT","0");
				comments = data.optString("COMMENT_COUNT","0");
				 shares = data.optString("SHARE_COUNT","0");
				time = data.getString("PROMULGATE_TIME");
				title = data.getString("CONTENT_TITLE");
				content = data.getString("INFO_CLIENT");
				
			}else{
				cllections = objt.optString("COLLECTION_COUNT","0");
				comments = objt.optString("COMMENT_COUNT","0");
				shares = objt.optString("SHARE_COUNT","0");
				time = data.getString("PROMULGATE_TIME");
				title = data.getString("NEWS_TITLE");
				content = data.getString("NEWS_CONTENT");	
			}
			
			/*boolean isCollection = FileUtils.isInterestCollection(newsId);
			collectionCheckBox.setChecked(isCollection);*/
			
			ServerCenterContentActivity.this.runOnUiThread(new Runnable() {
				
				@Override
				public void run() {
					//更新评论数量
					if(picPath==null||picPath.equals("")){
						imageViewContent.setVisibility(View.GONE);
					}else{
						mImageLoader.displayImage(picPath,imageViewContent, mDisplayImageOptions);
					}
					commenTextView.setText(comments+"");
					adapter.setCommentSize(comments);
//					titleTextV.setText(title);
					titleTextView.setText(title);
					contentTextView.setText(content);
					timeTextView.setText(time);
					collectionCheckBox.setText(cllections);
					shareTextView.setText(shares);
				}
			});

			
			if(data.has("CENTERMERCHANTNEWSPICTURE")){
				JSONObject jsonObject=data.getJSONObject("CENTERMERCHANTNEWSPICTURE");
				
				if(jsonObject.has("PICTURE_ADDR")){
					picPath = jsonObject.getString("PICTURE_ADDR");
				}
				
				if(imageViewContent==null){
					imageViewContent = new ImageView(this);
					imageViewContent.setClickable(true);
					imageViewContent.setOnClickListener(this);
					imageViewContent.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
					ServerCenterContentActivity.this.runOnUiThread(new Runnable() {
						@Override
						public void run() {
							mLinearLayout.addView(imageViewContent);
						}
					});
					urlList.add(picPath);
				}else{
					urlList.clear();
					urlList.add(picPath);
				}
			}else{
				if(data.has("PICTURES")){
					JSONArray array = data.getJSONArray("PICTURES");
					if(array.length()!=0){
						picPath=array.optJSONObject(0).optString("MENUPIC","");
					}
					if(imageViewContent==null){
						imageViewContent = new ImageView(this);
						imageViewContent.setClickable(true);
						imageViewContent.setOnClickListener(this);
						imageViewContent.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
						ServerCenterContentActivity.this.runOnUiThread(new Runnable() {
							@Override
							public void run() {
								mLinearLayout.addView(imageViewContent);
							}
						});
						urlList.add(picPath);
					}else{
						urlList.clear();
						urlList.add(picPath);
					}
					/*
					for (int i = 0; i < array.length(); i++) {
						JSONObject jsonObject = array.getJSONObject(i);
						String picPath= jsonObject.getString("MENUPIC");
						ImageView imageView = new ImageView(this);
						imageView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
						mLinearLayout.addView(imageView);
						imageView.setClickable(true);
						imageView.setOnClickListener(this);
						urlList.add(picPath);
						mImageLoader.displayImage(picPath,imageView, mDisplayImageOptions);
					}*/
				}
				
				
			}
			
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 查询评论
	 * @param type
	 */
	private void onDoQueryComment(final String type,final String lastId,String size){
		//第一次1,之后为0;
			HttpRestClient.doHttpQueryNewsComment(newsId,lastId,size,type,
					new JsonHttpResponseHandler(this){
				@Override
				public void onSuccess(int statusCode, JSONObject response) {
					super.onSuccess(statusCode, response);
					try {
						JSONArray jsonArray = response.getJSONArray("PARAMETER2");
						if("1".equals(type)){//查询之后的评论
							adapter.onDataChange(jsonArray,0);
							refreshListView.onRefreshComplete();
						}else if("0".equals(type)){//第一次查询
							adapter.onDataChange(jsonArray,0);
						}else if("-1".equals(type)){//查询之前的评论
							adapter.onDataChange(jsonArray,-1);
						}
					} catch (JSONException e) {
						e.printStackTrace();
					}
				}
				@Override
				public void onFinish() {
					super.onFinish();
					refreshListView.onRefreshComplete();
				}
			});
	}
	
	/**
	 * 显示新闻内容视图
	 * @return
	 * 
	 */
	private View onCreateContentView(){
		View view = LayoutInflater.from(this).inflate(R.layout.news_content_header_layout,null);
		mLinearLayout = (LinearLayout)view.findViewById(R.id.news_count_images);
		titleTextView = (TextView)view.findViewById(R.id.headerTxt);
		contentTextView = (TextView)view.findViewById(R.id.contentTxt);
		timeTextView = (TextView)view.findViewById(R.id.timeTxt);
		collectionCheckBox = (CheckBox)view.findViewById(R.id.news_collection);
		collectionCheckBox.setOnClickListener(this);
		
		shareTextView = (TextView)view.findViewById(R.id.news_share);
		shareTextView.setOnClickListener(this);
		commenTextView = (Button)view.findViewById(R.id.news_comment);
		commenTextView.setOnClickListener(this);
//		collectionCheckBox.setChecked(NewsUtil.isCollectionted(this,newsId));
		return view;
	}
	
	/**
	 * 通过短信
	 */
	private void shareNewsByMessage(){
		Intent intent = new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:"));
		intent.putExtra("sms_body", contentTextView.getText());
		startActivity(intent);
	}
	
	
	
	class NewsCommensAdapter extends BaseAdapter{
		List<JSONObject> list = new ArrayList<JSONObject>();
		final Context mContext;
		final LayoutInflater inflater;
		
		public NewsCommensAdapter(Context context){
			mContext = context;
			inflater = LayoutInflater.from(mContext);
			try {
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("SIZE",0);
				list.add(jsonObject);
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		
		@Override
		public int getCount() {
			return list.size();
		}
		
		private String getFirstId(){
			int length = list.size();
			if(length > 1){
				try {
					return getReplyId(getItem(1));
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}
			return "0";
		}

		@Override
		public JSONObject getItem(int position){
			return list.get(position);
		}

		public void clearData(){
			try {
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("SIZE",0);
				list.clear();
				list.add(jsonObject);
			} catch (JSONException e) {
			}
		}
		@Override
		public long getItemId(int position) {
			return position;
		}
		
		@Override
		public int getItemViewType(int position) {
			if(position == 0)return 1;
			return 2;
		}
		
		@Override
		public int getViewTypeCount() {
			return 3;
		}
		
		public void onDataChange(JSONArray array,int type){
			if(array.length() == 0)return;
			if(type == -1){//现在以后的评论
				for (int i = 0; i < array.length(); i++) {
					try {
						list.add(1, array.getJSONObject(i));
					} catch (JSONException e) {
						e.printStackTrace();
					}
				}
			}else{//现在以前的评论
				for (int i = 0; i < array.length(); i++) {
					try {
						list.add(array.getJSONObject(i));
					} catch (JSONException e) {
						e.printStackTrace();
					}
				}
			}
			notifyDataSetChanged();
		}
		
		/**
		 * 设置评论数量的大小
		 * @param zie
		 * @return
		 */
		public void setCommentSize(String zie){
			JSONObject jsonObject = getItem(0);
			try {
				jsonObject.put("SIZE",zie);
			} catch (JSONException e) {
				e.printStackTrace();
			}
			notifyDataSetChanged();
		}
		
		public String getCommentSize(){
			JSONObject jsonObject = getItem(0);
			String size = null;
			try {
				size = jsonObject.getString("SIZE");
			} catch (JSONException e) {
				e.printStackTrace();
			}
			return size;
		}
		
		public String getReplyId(JSONObject jsonobj)throws JSONException{
			return jsonobj.getString("REPLY_ID");
		}
		
		public String getNikeName(JSONObject jsonobj) throws JSONException{
			return jsonobj.getString("CUSTOMER_NICKNAME");
		}
		
		public String getTime(JSONObject jsonObject) throws JSONException{
			return jsonObject.getString("COMMENT_TIME");
		}

		public String getContent(JSONObject jsonObject) throws JSONException{
			return jsonObject.getString("COMMENT_CONTENT");
		}
		
		public String getHeadrImgPath(JSONObject jsonObject) throws JSONException{
			return jsonObject.getString("CLIENT_ICON_BACKGROUND");
		}
		
		public String getUserId(JSONObject jsonObject) throws JSONException{
			return jsonObject.getString("CUSTOMER_ID");
		}
		
		public String getSex(JSONObject jsonObject) throws JSONException{
			return jsonObject.getString("CUSTOMER_SEX");
		}
		
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			final int type = getItemViewType(position);
			final JSONObject jsonObject = getItem(position);
			final ViewHolder holder;
			
			if(convertView == null){
				if(type == 1){
					convertView = inflater.inflate(R.layout.news_comment_size_list_item,null);
					holder = new ViewHolder();
					convertView.setTag(holder);
				}else{
					convertView = inflater.inflate(R.layout.news_comment_list_item,null);
					holder = new ViewHolder();
					convertView.setTag(holder);
					
					holder.headerImageView = (ImageView)convertView.findViewById(R.id.head_image);
					holder.nameTextView = (TextView)convertView.findViewById(R.id.nameTxt);
					holder.timeTextView = (TextView)convertView.findViewById(R.id.timeTxt);
					holder.contentTextView = (TextView)convertView.findViewById(R.id.contentTxt);
					holder.repeatImageView = (ImageView)convertView.findViewById(R.id.comment_repeat);
				}
			}else{
				holder = (ViewHolder)convertView.getTag();
			}
			
			if(type == 1){
				((TextView)convertView).setText(getCommentSize()+"条评论");
			}else{
				try {
					String time = getTime(jsonObject);
					String name = getNikeName(jsonObject);
					String content = getContent(jsonObject);
					String headerPath = getHeadrImgPath(jsonObject);
					final String userId  = getUserId(jsonObject);
					final String replyId = getReplyId(jsonObject);
					holder.nameTextView.setText(name);
					//新闻内容
					holder.contentTextView.setText(content);
					holder.timeTextView.setText(time);
					holder.repeatImageView.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View v) {
							onComment(SmartFoxClient.getLoginUserId(), newsId, replyId);
						}
					});
					
					mImageLoader.displayImage(getSex(jsonObject),headerPath,holder.headerImageView);
					
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}
			return convertView;
		}
	}
	
	static class ViewHolder{
		TextView nameTextView;
		TextView timeTextView;
		TextView contentTextView;
		ImageView headerImageView;
		ImageView repeatImageView;
	}
	
	/**
	 * 分享成功时 更新服务器数据 分享数+1
	 */
	public void onShareSucceed() {
		actionForImage(newsId,userId, "updateCenterMerchantNewscount");
	}
	/**
	 * 分享到微博
	 * @param txt
	 * @param type
	 */
	public void shareTxt(int type){
		String txt = titleTextView.getText().toString().trim()+","+contentTextView.getText().toString().trim();
		if(txt.length()>65)
		txt=txt.substring(0, 65);
		txt=String.format(AppData.ShareContent, txt);
//		txt="我正在使用壹健康手机客户端看新闻:"+txt+"...更多内容查看：http://www.yijiankang.com/download.html";
		Bundle bundle = new Bundle();
		bundle.putString(OpenManager.BUNDLE_KEY_TEXT,txt);
		OpenManager openManager = OpenManager.getInstatnce();
		boolean isEnable = OpenManager.getInstatnce().isVaild(type,this);
		if(!isEnable)openManager.authorize(type,this);else{
		
		ShareDialogFragment.show(getSupportFragmentManager(),type,txt,null,new ShareDialogFragment.OnShareResultListener() {
			@Override
			public void onResult(int result) {
				if(result == 0){
					String size = shareTextView.getText().toString();
					if(NumberUtils.isNumber(size)){
						int commSize = Integer.valueOf(size)+1;
						shareTextView.setText(String.valueOf(commSize));
					}else{
						shareTextView.setText("1");
					}
					onShareSucceed();
				}
			}
		});}
	}
}
